package com.yeswater.multithread.chapter7;

/**
 * author : yeswater
 * date : 2023/11/6
 *
 * 线程组自动归属特性
 */

public class Run_7_2_3 {
    public static void main(String[] args) {
        System.out.println("A 处线程: " + Thread.currentThread().getName() + " 所属的线程组名为: "
                + Thread.currentThread().getThreadGroup().getName() + " 中有线程组数量: "
                + Thread.currentThread().getThreadGroup().activeGroupCount());
        ThreadGroup group = new ThreadGroup(" 新的组 ");
        System.out.println("B 处线程: " + Thread.currentThread().getName() + " 所属的线程组名为: "
                + Thread.currentThread().getThreadGroup().getName() + " 中有线程组数量: "
                + Thread.currentThread().getThreadGroup().activeGroupCount());
        ThreadGroup[] threadGroup = new ThreadGroup[Thread.currentThread().getThreadGroup().activeGroupCount()];
        Thread.currentThread().getThreadGroup().enumerate(threadGroup);
        for (ThreadGroup value : threadGroup) {
            System.out.println(" 第一个线程组名称为: " + value.getName());
        }
    }
}
